<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%--
	@auth : Conner
	@date : 2012-09-06
	@desc : 选择(权限资源)父节点
--%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择(权限资源)父节点</title>
<script type="text/javascript" src="<%=basePath%>js/public.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/lib/jquery/zTree/css/demo.css"/>
<link rel="stylesheet" href="<%=basePath%>js/lib/jquery/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
<jsp:include page="/admin/common/css/style_sub.jsp"></jsp:include>
<script type="text/javascript" src="<%=basePath%>js/lib/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/lib/jquery/zTree/js/jquery.ztree.core-3.3.js"></script>
<script type="text/javascript" src="<%=basePath%>js/lib/jquery/zTree/js/jquery.ztree.excheck-3.3.js"></script>
<script type="text/javascript">

var setting = {
	data: {
		key: {
			title:"remark",
			name:"name"
		},
		simpleData: {
			enable: true,
			idKey: "id",
			pIdKey: "pId"
		}
	},
	check: {
		enable: true,
		chkStyle: "radio",
		radioType: "all"
	},
	view: {
		dblClickExpand: dblClickExpand ,
		selectedMulti: false
	},
	callback: {                 
		beforeDrag: false,
		onClick: onClick
	}
};
var arr;  //存放权限id, level(层级)的二维数组
$(function(){
	//获取父页面传递过来的参数值
	var element = window.dialogArguments;
	var sub_id = element;  //子系统id 
	if(element.length == 0){
		return;
	}
	var params = {
		ct: (new Date()).getTime(),
		'right.sub_id' : sub_id
	};
	$.getJSON("<%=basePath%>basic/sys/right_findAllRightBySubId.action", params, function(json){
		if(json.resultCode == 'success'){
			arr = new Array();
			if(json.list.length > 0){
				json.list[0].open = true;
				json.list[0].nocheck = false;
				//arr = new Array(json.list.length, 2); 
				for(var i = 0 ; i < json.list.length ; i++){
					arr[i] = new Array();    //在声明二维
					arr[i][0] = json.list[i].id;
					arr[i][1] = json.list[i].level_;
					//alert(arr[i][0]);
				}
				G("nDiv").value = json.list.length;
				G("tDiv").style.display = "block";
				$.fn.zTree.init($("#treeDemo"), setting, json.list);
			}else if(json.list.length == 0){
				G("nDiv").value = 0;
				G("cDiv").style.display = "none";
				G("aDiv").style.display = "block";
				G("aDiv").innerHTML = "<font>该系统下暂无权限资源信息</font>";
			}
		}else{
			alert("加载权限资源信息失败!");
		}
	});
});

function dblClickExpand(treeId, treeNode) {
	return treeNode.o_level > 0;
}

function onClick(event, treeId, treeNode, clickFlag) {
	
}
//提交内容
function tiJiao(){
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var nodes = treeObj.getCheckedNodes(true);
	var selectObj = "0,无,0";
	var level = "";
	var id;
	//alert("nodes.length="+nodes.length);
	if(nodes.length == 1){
		for (var i = 0; i < nodes.length; i++) {
			id = nodes[i].id;
			//根据id, 找到层级
			for(var j = 0 ; j < arr.length ; j++){
				if(arr[j][0] == id){
					level = arr[j][1];
					break;
				}
			}
			selectObj = id + "," + nodes[i].name + "," + level;
			//alert(selectObj);
		}
		window.returnValue = selectObj;
		window.close();
	}else if(nodes.length == 0){
		alert("请选择父节点！");
	}
}

//返回
function closeWin(){
	if(G("nDiv").value == 0){
		var selectObj = "0,无,0";
		window.returnValue = selectObj;
	}
	window.close();
}
</script>
<style type="text/css">
.ztree li ul.level0 {padding:0; background:none;}
ul.ztree {margin-top:0px;border: 0px solid #617775;background: #FFFFFF;
		  width:230px;height:360px;overflow-y:auto;overflow-x:auto;}
</style>
</head>
<body style="overflow:hidden;">
		<div id="aDiv" style="display:none;height:370px;"></div>
		<div id="tDiv" class="left" style="display:none;margin:0px;">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
		<div style="width:100%;height:40px;line-height:40px;background:#EEEEEE;float:bottom;">
			<div align="center">
				<input type="hidden" id="nDiv" value=""/>
				<input type="button" id="cDiv" onclick="javascript:tiJiao();" value="确定"/>&nbsp;&nbsp;
				<input type="button" onclick="javascript:closeWin();" value="返回"/>
			</div>
		</div>
</body>
<script>
sx();
function sx(){
	document.title = "选择(权限资源)父节点";
}
</script>
</html>